<?php
  $objXajax->registerFunction("fmfrmroomtype_save");
  $objXajax->registerFunction("fmfrmroomtype_edit");
  $objXajax->registerFunction("fmfrmroomtype_delete");
  $objXajax->registerFunction("fmfrmroomtype_loadGrid");
  function fmfrmroomtype_save($params){     
    global $objDbSelect,$user_id,$hotel_id;
    $objResponse = new xajaxResponse();
    $name = addslashes(strip_tags($params['txtnametype']));
    $style = $params['cbbstyle'];  
    $minmoney = $params['txtminmoney'];  
    $id = $params['hdId'];
    $edit = $params['hdEdit'];
    $flag = true;

    $sql ='';
    if($params['hdEdit']==1){
        $sql = "update fm_room_type set name ='$name', style='$style',extprice='$minmoney',
        date_update=now(),user_update='$user_id' WHERE id='$id' ";
        //$flag = $objDbUpdate->Execute($sqlUpdate);  
    }else{
        $sql = "insert into fm_room_type(name,style,date_created,date_update,user_created,user_update,service_id,extprice)
        value('$name','$style',now(),now(),'$username','$username',$hotel_id,'$minmoney')";
        //$flag = $objDbUpdate->Execute($sqlInsert);
        $objResponse->addScript("changeUpdate('fmfrmroomtype',$id);");  
    }
      if($objDbSelect->Execute($sql)){
       $objResponse->addScript("checkUpdateStatus(1,'fmfrmroomtype','$edit');");
       $objResponse->addScript('xajax_fmfrmroomtype_loadGrid();'); 
        }else{
       $objResponse->addScript("checkUpdateStatus(0,'fmfrmroomtype','$edit');");
    } 
    $objResponse->addScript("hasChange= true;");
     //$objResponse->addScript('xajax_fmfrmroomtype_loadGrid();');    
      return $objResponse->getXML(); 
  }
  
   function fmfrmroomtype_loadGrid(){
    global $lang;
    $objResponse = new xajaxResponse();
    $arrGrid = fmfrmroomtype_GetGrid();
    $oTbs = new clsTinyButStrong();
    $oTbs->LoadTemplate('templates/'.$lang.'/customer/fm_roomtype_grid.html');
    $oTbs->MergeBlock('blk_data', $arrGrid);
    $oTbs->Show(TBS_NOTHING);
    $objResponse->addAssign('fmfrmroomtype_divGrid', 'innerHTML', $oTbs->Source);
    $objResponse->addScriptCall("dataTableObj.CreatDataTable('fmfrmroomtype_tbl');");
    $objResponse->addScript('changeWaiting(1);');                               
    return $objResponse->getXML(); // dong luon luon co khi goi ham ajax   
  }
  
    function  fmfrmroomtype_GetGrid(){
        global $objDbSelect,$hotel_id;
        $sqlSelect = "select * from fm_room_type WHERE service_id ='$hotel_id'  order by name";
        return $objDbSelect->GetArray($sqlSelect);
    }
    function fmfrmroomtype_delete($strId){
        global $objDbSelect;
       $objResponse = new xajaxResponse();
       $sql = " delete from fm_room where room_type in ($strId) " ;
       if($objDbSelect->Execute($sql)){
           $sql = " delete from fm_room_type where id in ($strId) " ; 
       }
       $objResponse->addScript('changeWaiting(1);');
       $objResponse->addScript('deleteRowlogic();');
       return $objResponse->getXML(); // dong luon luon co khi goi ham ajax  
    }
    
    function fmfrmroomtype_edit($id){
       global $objDbSelect;
       $objResponse = new xajaxResponse();
       $sql = " SELECT *  FROM fm_room_type WHERE id = '$id' ";

       $arr = $objDbSelect->GetArray($sql);
      $style        = $arr[0]['style'];
      $name         = $arr[0]['name'];                                              
      $extprice         =FormatMoney($arr[0]['extprice']) ;
      
      $description =htmlspecialchars_decode($arr[0]['description']) ;
      $objResponse->addAssign('fmfrmroomtype_txtminmoney','value',$description);                                              
                                           
      $objResponse->addScript("$('#fmfrmroomtype_txtnametype').val('$name');");
      $objResponse->addScript("$('#fmfrmroomtype_cbbstyle-$style').attr('checked',true);");
      $objResponse->addScript("$('#fmfrmroomtype_txtminmoney').val('$extprice');");
        
      $objResponse->addScript('changeWaiting(1);');
      return $objResponse->getXML();   
    }
?>
